﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CRM.DataAccess.Entities;
using Telerik.Web.UI;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Configuration;

namespace Web
{
    public partial class Site : System.Web.UI.MasterPage
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Page.Header.DataBind();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;
            USER user = (USER)Session["User"];

            if (this.Page.User.Identity.IsAuthenticated && user != null)
            {
                if (user != null)
                {
                   // lblUsername.Text = user.USER_NAME + "&nbsp";
                   
                    imgAvatar.Attributes["src"] = user.IMAGE;
                    liManagerUser.Visible = (bool)user.IS_ADMIN;
                    hrBelowManagerUsers.Visible = liManagerUser.Visible;
                    liManagerRole.Visible = user.IS_ADMIN == true ? true : false;
                    hrBelowManagerRoles.Visible = liManagerRole.Visible;
                }
            }
            else
                Response.Redirect("~/Account/Login.aspx");
        }

        protected void lbtnMyProfile_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Account/MyProfile.aspx");
        }

        protected void lbtnManagerUsers_Click(object sender, EventArgs e)
        {
            if (this.Page.User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/Account/Users.aspx");
            }
        }
        protected void lbtnManagerRoles_Click(object sender, EventArgs e)
        {
            if (this.Page.User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/Account/Roles.aspx");
            }
        }

        protected void lbtnSignOut_Click(object sender, EventArgs e)
        {
            if (this.Page.User.Identity.IsAuthenticated)
            {
                Session["User"] = null;
                FormsAuthentication.SignOut();
            }

            Response.Redirect("~/Account/Login.aspx");
        }

        protected void RadScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
        {
            string t = e.Exception.Message;
        }
        protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
        {
            if (e.Argument == "InitialPageLoad")
            {
                //simulate longer page load        
                System.Threading.Thread.Sleep(1000);
                Panel1.Style["display"] = "block";
            }
        }
    }
}